﻿// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#pragma once

    /// <summary>
    /// Value indicating the general character set for a given character.
    /// </summary>
enum class CharacterType
{
    /// <summary>
    /// Indicates we could not match the character set.
    /// </summary>
    Other = 0,

    /// <summary>
    /// Member of the Latin character set.
    /// </summary>
    Standard = 1,

    /// <summary>
    /// Member of a symbolic character set.
    /// </summary>
    Symbolic = 2,

    /// <summary>
    /// Member of a character set which supports glyphs.
    /// </summary>
    Glyph = 3
};

/// <summary>
/// PersonPicture Control. Displays the Profile Picture, or in its absence Initials,
/// for a given Contact.
/// </summary>
class InitialsGenerator
{
public:
    /// <summary>
    /// Helper function which takes a DisplayName, as generated by
    /// Windows.ApplicationModel.Contacts, and returns a initials representation.
    /// </summary>
    /// <returns>
    /// String containing the initials representation of the given DisplayName.
    /// </returns>
    static winrt::hstring InitialsFromContactObject(const winrt::Contact &contact);

    /// <summary>
    /// Helper function which takes a DisplayName, as generated by
    /// Windows.ApplicationModel.Contacts, and returns a initials representation.
    /// </summary>
    /// <param name="contactDisplayName>The DisplayName of the person</param>
    /// <returns>
    /// String containing the initials representation of the given DisplayName.
    /// </returns>
    static winrt::hstring InitialsFromDisplayName(const wstring_view &contactDisplayName);

    /// <summary>
    /// Helper function which indicates the type of characters in a given string
    /// </summary>
    /// <param name="str">String from which to detect character-set.</param>
    /// <returns>
    /// Character set of the string: Latin, Symbolic, Glyph, or other.
    /// </returns>
    static CharacterType GetCharacterType(const wstring_view &str);

    /// <summary>
    /// Helper function which indicates the character-set of a given character.
    /// </summary>
    /// <param name="character">Character for which to detect character-set.</param>
    /// <returns>
    /// Character set of the string: Latin, Symbolic, Glyph, or other.
    /// </returns>
    static CharacterType GetCharacterType(wchar_t character);

private:
    /// <summary>
    /// Helper function which takes in a string and returns a vector of pieces, separated by delimiter.
    /// </summary>
    /// <param name="source">String on which to perform the split operation.</param>
    /// <param name="delim">String on which to perform the split operation.</param>
    /// <param name="maxIterations">Maximum number of times to perform a <code>getline</code> loop.</param>
    /// <returns>A vector of pieces from the source string, separated by delimiter</returns>
    static std::vector<std::wstring> Split(const std::wstring &source, wchar_t delim, int maxIterations = 25);

    /// <summary>
    /// Helper function to remove bracket qualifier from the end of a display name if present.
    /// </summary>
    /// <param name="source">String on which to perform the operation.</param>
    /// <returns>A string with the content within brackets removed.</returns>
    static void StripTrailingBrackets(std::wstring &source);

    /// <summary>
    /// Extracts the first full character from a given string, including any diacritics or combining characters.
    /// </summary>
    /// <param name="str">String from which to extract the character.</param>
    /// <returns>A wstring which represents a given character.</returns>
    static std::wstring GetFirstFullCharacter(const std::wstring &str);
};
